import { observable, action, computed } from 'mobx';
import * as  Apis from '../apis/govern';
import _ from "lodash";
import { ListStore } from './listStore';
import { message, Modal } from 'antd';
import { WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

export class GovernShareStore extends ListStore {
    @observable tasklabels = {};
    @observable status = {
        loading: false,
    }
    @observable id;
    @observable showAdd = false;
    @observable showMessage = true;

    oldshareCondition = [
        {
            "colSpan": 2,
            "conditionType": "SELECT",
            "domkey": [
                "sharetype"
            ],
            "fieldcol": 18,
            "isQuickSearch": false,
            "label": getLabel(21956, "对象类型"),
            "labelcol": 6,
            "options": [
                {
                    "key": "1",
                    "selected": true,
                    "showname": getLabel(179, "人力资源")
                }, {
                    "key": "2",
                    "selected": false,
                    "showname": getLabel(124, "部门")
                }, {
                    "key": "3",
                    "selected": false,
                    "showname": getLabel(141, "分部")
                }, {
                    "key": "4",
                    "selected": false,
                    "showname": getLabel(122, "角色")
                }, {
                    "key": "5",
                    "selected": false,
                    "showname": getLabel(1340, "所有人")
                }, {
                    "key": "6",
                    "selected": false,
                    "showname": getLabel(6086, "岗位")
                }
            ],
            "viewAttr": 2
        }, {
            "1": [[
                {
                    "browserConditionParam": {
                        "completeParams": {},
                        "conditionDataParams": {},
                        "dataParams": {},
                        "destDataParams": {},
                        "hasAddBtn": false,
                        "hasAdvanceSerach": true,
                        "idSeparator": ",",
                        "isAutoComplete": 1,
                        "isDetail": 0,
                        "isMultCheckbox": false,
                        "isSingle": false,
                        "pageSize": 10,
                        "quickSearchName": "",
                        "type": "17",
                        "viewAttr": 3,
                        "title":getLabel(106, "对象")
                    },
                    "colSpan": 2,
                    "conditionType": "BROWSER",
                    "domkey": [
                        "relatedid"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(106, "对象"),
                    "labelcol": 6,
                    "viewAttr": 3,
                    "title":getLabel(106, "对象")
                }
            ], [
                {
                    "colSpan": 2,
                    "conditionType": "SELECT",
                    "domkey": [
                        "opttype"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(385, "权限"),
                    "labelcol": 6,
                    "options": [
                        {
                            "key": "1",
                            "selected": true,
                            "showname": getLabel(33564, "查看")
                        }, {
                            "key": "2",
                            "selected": false,
                            "showname": getLabel(119, "共享")
                        }
                    ],
                    "viewAttr": 2
                }
            ]
            ],
            "3": [[
                {
                    "browserConditionParam": {
                        "completeParams": {},
                        "conditionDataParams": {},
                        "dataParams": {},
                        "destDataParams": {},
                        "hasAddBtn": false,
                        "hasAdvanceSerach": true,
                        "idSeparator": ",",
                        "isAutoComplete": 1,
                        "isDetail": 0,
                        "isMultCheckbox": false,
                        "isSingle": false,
                        "pageSize": 10,
                        "quickSearchName": "",
                        "type": "194",
                        "viewAttr": 3,
                         "title":getLabel(106, "对象")
                    },
                    "colSpan": 2,
                    "conditionType": "BROWSER",
                    "domkey": [
                        "relatedid"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(106, "对象"),
                    "labelcol": 6,
                    "value": 3,
                    "viewAttr": 2,
                    "title":getLabel(106, "对象")
                }
            ], [
                {
                    "colSpan": 2,
                    "conditionType": "INPUT_INTERVAL",
                    "domkey": [
                        "seclevel",
                        "seclevel2"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(683, "安全级别"),
                    "labelcol": 6,
                    "value": [
                        0,
                        ''
                    ],
                    "viewAttr": 3,
                    "needDefaultValue":false
                }
            ], [
                {
                    "colSpan": 2,
                    "conditionType": "SELECT",
                    "domkey": [
                        "opttype"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(385, "权限"),
                    "labelcol": 6,
                    "options": [
                        {
                            "key": "1",
                            "selected": true,
                            "showname": getLabel(33564, "查看")
                        }, {
                            "key": "2",
                            "selected": false,
                            "showname": getLabel(119, "共享")
                        }
                    ],
                    "viewAttr": 2
                }
            ]
            ],
            "2": [[
                {
                    "browserConditionParam": {
                        "completeParams": {},
                        "conditionDataParams": {},
                        "dataParams": {},
                        "destDataParams": {},
                        "hasAddBtn": false,
                        "hasAdvanceSerach": true,
                        "idSeparator": ",",
                        "isAutoComplete": 1,
                        "isDetail": 0,
                        "isMultCheckbox": false,
                        "isSingle": false,
                        "pageSize": 10,
                        "quickSearchName": "",
                        "type": "57",
                        "viewAttr": 3,
                        "title":getLabel(106, "对象")
                    },
                    "colSpan": 2,
                    "conditionType": "BROWSER",
                    "domkey": [
                        "relatedid"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(106, "对象"),
                    "labelcol": 6,
                    "viewAttr": 3,
                    "title":getLabel(106, "对象")
                }
            ], [
                {
                    "colSpan": 2,
                    "conditionType": "INPUT_INTERVAL",
                    "domkey": [
                        "seclevel",
                        "seclevel2"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(683, "安全级别"),
                    "labelcol": 6,
                    "value": [
                        0,
                        ''
                    ],
                    "viewAttr": 3,
                    "needDefaultValue":false
                }
            ], [
                {
                    "colSpan": 2,
                    "conditionType": "SELECT",
                    "domkey": [
                        "opttype"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(385, "权限"),
                    "labelcol": 6,
                    "options": [
                        {
                            "key": "1",
                            "selected": true,
                            "showname": getLabel(33564, "查看")
                        }, {
                            "key": "2",
                            "selected": false,
                            "showname": getLabel(119, "共享")
                        }
                    ],
                    "viewAttr": 2
                }
            ]
            ],
            "5": [
                [
                    {
                        "colSpan": 2,
                        "conditionType": "INPUT_INTERVAL",
                        "domkey": [
                            "seclevel",
                            "seclevel2"
                        ],
                        "fieldcol": 18,
                        "isQuickSearch": false,
                        "label": getLabel(683, "安全级别"),
                        "labelcol": 6,
                        "value": [
                            0,
                            ''
                        ],
                        "viewAttr": 3,
                        "needDefaultValue":false
                    }
                ], [
                    {
                        "colSpan": 2,
                        "conditionType": "SELECT",
                        "domkey": [
                            "opttype"
                        ],
                        "fieldcol": 18,
                        "isQuickSearch": false,
                        "label": getLabel(385, "权限"),
                        "labelcol": 6,
                        "options": [
                            {
                                "key": "1",
                                "selected": true,
                                "showname": getLabel(33564, "查看")
                            }, {
                                "key": "2",
                                "selected": false,
                                "showname": getLabel(119, "共享")
                            }
                        ],
                        "viewAttr": 2
                    }
                ]
            ],
            "4": [[
                {
                    "browserConditionParam": {
                        "completeParams": {},
                        "conditionDataParams": {},
                        "dataParams": {},
                        "destDataParams": {},
                        "hasAddBtn": false,
                        "hasAdvanceSerach": true,
                        "idSeparator": ",",
                        "isAutoComplete": 1,
                        "isDetail": 0,
                        "isMultCheckbox": false,
                        "isSingle": false,
                        "pageSize": 10,
                        "quickSearchName": "",
                        "type": "65",
                        "viewAttr": 3,
                        "title":getLabel(106, "对象")
                    },
                    "colSpan": 2,
                    "conditionType": "BROWSER",
                    "domkey": [
                        "relatedid"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(106, "对象"),
                    "labelcol": 6,
                    "viewAttr": 3,
                    "title":getLabel(106, "对象")
                }, {
                    "colSpan": 2,
                    "conditionType": "SELECT",
                    "domkey": [
                        "rolelevel"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(139, "级别"),
                    "labelcol": 6,
                    "options": [
                        {
                            "key": "0",
                            "selected": true,
                            "showname": getLabel(124, "部门")
                        }, {
                            "key": "1",
                            "selected": false,
                            "showname": getLabel(141, "分部")
                        }, {
                            "key": "2",
                            "selected": false,
                            "showname": getLabel(140, "总部")
                        }
                    ],
                    "viewAttr": 2
                }
            ], [
                {
                    "colSpan": 2,
                    "conditionType": "INPUT_INTERVAL",
                    "domkey": [
                        "seclevel",
                        "seclevel2"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(683, "安全级别"),
                    "labelcol": 6,
                    "value": [
                        0,
                        ''
                    ],
                    "viewAttr": 3,
                    "needDefaultValue":false
                }
            ], [
                {
                    "colSpan": 2,
                    "conditionType": "SELECT",
                    "domkey": [
                        "opttype"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(385, "权限"),
                    "labelcol": 6,
                    "options": [
                        {
                            "key": "1",
                            "selected": true,
                            "showname": getLabel(33564, "查看")
                        }, {
                            "key": "2",
                            "selected": false,
                            "showname": getLabel(119, "共享")
                        }
                    ],
                    "viewAttr": 2
                }
            ]
            ],
            "6": [[
                {
                    "browserConditionParam": {
                        "completeParams": {},
                        "conditionDataParams": {},
                        "dataParams": {},
                        "destDataParams": {},
                        "hasAddBtn": false,
                        "hasAdvanceSerach": true,
                        "idSeparator": ",",
                        "isAutoComplete": 1,
                        "isDetail": 0,
                        "isMultCheckbox": false,
                        "isSingle": false,
                        "pageSize": 10,
                        "quickSearchName": "",
                        "type": "278",
                        "viewAttr": 3,
                         "title":getLabel(106, "对象")
                    },
                    "colSpan": 2,
                    "conditionType": "BROWSER",
                    "domkey": [
                        "relatedid"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(106, "对象"),
                    "labelcol": 6,
                    "viewAttr": 3,
                    "title":getLabel(106, "对象")
                }
            ], [
                {
                    "colSpan": 2,
                    "conditionType": "SELECT_LINKAGE",
                    "domkey": [
                        "joblevel"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(28169, "岗位级别"),
                    "labelcol": 6,
                    "options": [
                        {
                            "key": "2",
                            "selected": true,
                            "showname": getLabel(140, "总部")
                        }, {
                            "key": "1",
                            "selected": false,
                            "showname": getLabel(19437, "指定分部")
                        }, {
                            "key": "0",
                            "selected": false,
                            "showname": getLabel(19438, "指定部门")
                        }
                    ],
                    "selectLinkageDatas": {
                        "1": {
                            "browserConditionParam": {
                                "completeParams": {},
                                "conditionDataParams": {},
                                "dataParams": {},
                                "destDataParams": {},
                                "hasAddBtn": false,
                                "hasAdvanceSerach": true,
                                "idSeparator": ",",
                                "isAutoComplete": 1,
                                "isDetail": 0,
                                "isMultCheckbox": false,
                                "isSingle": false,
                                "pageSize": 10,
                                "quickSearchName": "",
                                "type": "194",
                                "viewAttr": 3,
                                 "title":getLabel(106, "对象")
                            },
                            "colSpan": 2,
                            "conditionType": "BROWSER",
                            "domkey": [
                                "jobleveltextsubcompany"
                            ],
                            "fieldcol": 18,
                            "isQuickSearch": false,
                            "label": "",
                            "labelcol": 6,
                            "viewAttr": 3,
                            "title":getLabel(106, "对象")
                        },
                        "0": {
                            "browserConditionParam": {
                                "completeParams": {},
                                "conditionDataParams": {},
                                "dataParams": {},
                                "destDataParams": {},
                                "hasAddBtn": false,
                                "hasAdvanceSerach": true,
                                "idSeparator": ",",
                                "isAutoComplete": 1,
                                "isDetail": 0,
                                "isMultCheckbox": false,
                                "isSingle": false,
                                "pageSize": 10,
                                "quickSearchName": "",
                                "type": "57",
                                "viewAttr": 3,
                                 "title":getLabel(106, "对象")
                            },
                            "colSpan": 2,
                            "conditionType": "BROWSER",
                            "domkey": [
                                "jobleveltextdepartment"
                            ],
                            "fieldcol": 18,
                            "isQuickSearch": false,
                            "label": "",
                            "labelcol": 6,
                            "viewAttr": 3,
                            "title":getLabel(106, "对象")
                        }
                    },
                    "viewAttr": 2
                }
            ], [
                {
                    "colSpan": 2,
                    "conditionType": "SELECT",
                    "domkey": [
                        "opttype"
                    ],
                    "fieldcol": 18,
                    "isQuickSearch": false,
                    "label": getLabel(385, "权限"),
                    "labelcol": 6,
                    "options": [
                        {
                            "key": "1",
                            "selected": true,
                            "showname": getLabel(33564, "查看")
                        }, {
                            "key": "2",
                            "selected": false,
                            "showname": getLabel(119, "共享")
                        }
                    ],
                    "viewAttr": 2
                }
            ]
            ]
        }
    ]
    @observable appDetachDisableAll = false;//是否禁用“所有人”权限范围
    newshareCondition = JSON.parse(JSON.stringify(this.oldshareCondition)) ;
    num = 0;
    @computed get shareCondition(){
        if(this.num < 1)
        this.newshareCondition[0].options.splice(4,1);
        return this.appDetachDisableAll ? this.newshareCondition : this.oldshareCondition;
    }
    @action
    setId(params = {}) {
        this.id = params.id;
    }
    @action
    ShowMessage = (bool)=>{
        this.showMessage = bool;
    }
    //共享提交接口  
    @action
    getShareList = () => {
        this.status.loading = true;
        Apis.getShareList({ id: this.id }).then(data => {
            if(parseInt(data.status) == 1){
              this.tableStoreMyAttent.getDatas(data.sessionkey, 1);
            }else{
              message.error(data.error);
            }
            this.status.loading = false;
        }).catch(error => {
            message.error(error);
        });
    }

    @action
    onShowAdd = (flag) => {
        this.showAdd = flag;
        if(this.showAdd === true){
            Apis.getAppDetachDisableAll().then((data)=>{
                if(data.status === "1"){
                    this.num ++ ; 
                    this.appDetachDisableAll = data.appDetachDisableAll;
                }
            }).catch((err)=>{
                throw err;
            })
        }
        
    }

    @action
    addShare = (params = {}) => {
        Apis.addShare({ id: this.id, ...params }).then(data => {
            if(parseInt(data.status) == 1){
              if (data.status == "1") {
                  this.showAdd = false;
                  this.showMessage ? message.success(getLabel('119,15242',"共享成功")) : null;
                  this.getShareList();
              } else {
                  message.error(getLabel(119, "共享") + getLabel(32140, "异常，请联系管理员!"));
              }
            }else{
              message.error(data.error);
            }
        }).catch(error => {
            message.error(error);
        })
    }
}
